Skip to content

fix(aggregate-api): 修复强校验供应商连通性测试 - #451

Open
goubo wants to merge 1 commit into
qxcnm:mainfrom
goubo:fix/0-aggregate-api-probe-user-agent
Open

fix(aggregate-api): 修复强校验供应商连通性测试#451
goubo wants to merge 1 commit into
qxcnm:mainfrom
goubo:fix/0-aggregate-api-probe-user-agent

Conversation

@goubo

@goubo goubo commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

变更摘要

  • 修复聚合 API 管理页“测试 route”在上游供应商强制校验 Codex 官方客户端时误报 403 的问题。
  • 新增连通性测试客户端标识设置,默认模拟 Codex 官方客户端请求头,也支持管理员指定自定义 User-Agent
  • 默认 Codex profile 为独立 probe 补齐 User-Agentoriginatorsession-idthread-idx-client-request-idx-codex-window-id;正常 route 转发逻辑保持不变。

改动范围

  • Frontend
  • Desktop / Tauri
  • Service
  • Gateway / Protocol Adapter
  • Docs / Governance
  • Workflow / Release

主要文件

  • crates/service/src/aggregate_api.rs:按设置为 Codex probe 构建官方客户端标识或自定义 UA。
  • crates/service/src/app_settings/aggregate_api.rs:新增设置默认值、持久化、模式与 UA 校验。
  • crates/service/src/aggregate_api_tests.rscrates/service/src/app_settings/aggregate_api_settings_tests.rs:覆盖默认 Codex profile、自定义 UA 与设置校验。
  • apps/src/app/aggregate-api/page.tsx:新增连通性测试设置入口与响应式配置 Dialog。
  • apps/src/types/settings.tsapps/src/lib/api/normalize.tsapps/src/lib/store/useAppStore.ts:同步前端设置类型、normalize 与默认状态。
  • docs/zh-CN/report/聚合API请求规则与配置说明.md:补充设置语义和请求头说明。

验证

  • pnpm -C apps run test
  • pnpm -C apps run build
  • pnpm -C apps run test:ui
  • cargo test --workspace
  • 其他本地验证已说明

已执行的实际验证:

node --test
结果:191/191 通过;等价于 apps/package.json 中 pnpm run test -> pnpm run test:runtime -> node --test。

./node_modules/.bin/next build
结果:通过;TypeScript、production build 和 19 个静态页面生成成功,等价于 pnpm run build/build:desktop 的实际脚本。

PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=<本机 Edge> pnpm run test:ui
结果:34/36 通过;2 个失败均与本 PR 修改路径无关,见“未执行的验证与原因”。

cargo fmt --all -- --check
结果:通过(官方 rust:1-bookworm 容器)。

cargo check --workspace --all-targets
结果:通过;仅有 upstream 既有 unused import warning。

cargo test --workspace -- --test-threads=1
结果:core 405/405、service unit 1433/1433(3 ignored)及其他 workspace suites 通过;gateway_logs 有 3 个 upstream 基线失败,见下方说明。

cargo test -p codexmanager-service aggregate_api -- --test-threads=1
结果:51 个相关 unit tests、4 个 gateway integration tests、1 个 settings integration test 通过。

cargo test -p codexmanager-service app_settings -- --test-threads=1
结果:12 个内部测试、26 个 integration tests、2 个 RPC tests 通过。

隔离数据库 live probe:升哥 / https://sub2.uimock.com
结果:默认 Codex profile 成功通过供应商强制客户端校验;未读取或输出密钥,未修改原服务数据库。

变更文件 ESLint、git diff --check
结果:通过。

未执行的验证与原因:

pnpm -C apps run test:ui 未标记为全量通过:
1. codex-cli-onboarding.spec.ts 仍查找 upstream 当前 UI 已不存在的 data-testid="codex-guide-step-title",收到 0,期望 3。
2. codex-skills-marketplace.spec.ts 在 Microsoft Edge/macOS 上测得 scrollbar 宽 11px,测试硬编码期望 12px。
本 PR 未修改 onboarding、skills marketplace 或 scrollbar 组件;其余 34 个 UI 用例通过。

cargo test --workspace 未标记为全量通过:
gateway_logs 有 3 个失败:
1. gateway_claude_failover_cross_workspace_strips_session_affinity_headers
2. gateway_claude_failover_same_workspace_preserves_session_affinity_headers
3. gateway_usage_limit_after_semantic_delta_does_not_fail_over_same_request
以上 3 个用例均已在 detached upstream/main@b266979b 的干净 worktree 中独立复现,确认属于上游基线问题;本 PR 的 aggregate_api/app_settings 定向测试全部通过。

未执行本地 Tauri macOS bundle:本 PR 未修改 Tauri/desktop shell;上游 CI 会执行 macOS arm64 bundle。

风险与影响面

  • 设置只作用于聚合 API 的独立连通性 probe,不改变正常 route 请求转发、Gateway 账号池或 Claude/Gemini probe。
  • 自定义模式只发送管理员指定的 User-Agent,不会附加 Codex fingerprint headers。
  • 自定义 UA 必填,禁止 ASCII 控制字符,最大 512 bytes,避免无效 header 和 header injection。
  • 默认模式会模拟 Codex 官方客户端标识,目的是让 probe 与实际 Codex route 的供应商准入规则一致。
  • 新设置通过现有 app settings API 同步到 desktop/service/web 三种运行模式,无数据库 schema 迁移。

未拆分说明

  • crates/service/src/aggregate_api.rs 是现有 probe 请求构建入口,本次只在原 add_codex_probe_headers 中选择 header profile;设置校验与持久化已拆到新的 app_settings/aggregate_api.rs,继续拆分请求构建会扩大调用边界而没有减少本次风险。
  • apps/src/app/aggregate-api/page.tsx 当前低于 800 行强制拆分阈值;本次 Dialog 直接复用页面已有 app settings 状态和 mutation,保持局部修改,未引入新的跨页面业务抽象。

备注

  • 已确认提交不包含 API key、token、cookie、本机数据库或测试凭据。
  • agent-work-dir/ 未包含在提交中。
  • 建议使用 Squash Merge。

部分供应商仅接受 Codex 官方客户端标识,原有 probe 请求缺少完整指纹,导致已配置路由被误判为不可用。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant